//
//  OriginData.m
//  礼物说
//
//  Created by shmily on 15/8/17.
//  Copyright (c) 2015年 shmilyAshen. All rights reserved.
//

#import "OriginData.h"

@implementation OriginData

// 单例
+ (instancetype)sharedOriginData {
    static OriginData *singleToken;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        singleToken = [OriginData new];
    });
    return singleToken;
}

- (NSNumber *)gender {
    if (_generation == nil) {
        [self readFromUserDefaults];
    }
    return self.gender;
}

- (NSNumber *)generation {
    if (_generation == nil) {
        [self readFromUserDefaults];
    }
    return self.generation;
}

- (void)WriteToUserDefault {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setValue:self.gender forKey:@"gender"];
    [userDefault setValue:self.gender forKey:@"generation"];
}

- (void)readFromUserDefaults {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    self.gender = [userDefault valueForKey:@"gender"] ;
    self.generation = [userDefault valueForKey:@"generation"];
}

@end
